package tcpdemo.tcptest1;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        // 创建客户端
        Socket socket = new Socket("127.0.0.1",10000);
        // 获取输出流，写入数据
        OutputStream os = socket.getOutputStream();
        os.write("hello".getBytes());
        socket.shutdownOutput();// 仅仅关闭输出流

        /*InputStream is = socket.getInputStream();
        int b;
        while ((b = is.read())!= -1){
            System.out.println((char)b);
        }*/
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line;
        while ((line = br.readLine())!=null){
            System.out.println(line);
        }

        socket.close();
        os.close();
        br.close();
    }
}
